﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using VideoSeller.Business.Models;
using VideoSeller.Web.Models;

namespace VideoSeller.Web.Controllers
{
	[Authorize]
    public class InfoController : BaseController
	{
		private readonly FeedbackTypeModel _feedbackTypeModel;
		private readonly MailModel _mailModel;

		public InfoController(FeedbackTypeModel feedbackTypeModel, MailModel mailModel)
		{
			_feedbackTypeModel = feedbackTypeModel;
			_mailModel = mailModel;
		}

		[HttpGet]
        public ActionResult Feedback()
		{
			var model = new FeedbackViewModel
				{
					FeedbackTypes = _feedbackTypeModel.GetAll().OrderBy(x => x.Name).Select(x => x.Name).ToList()
				};
            return View(model);
        }

		[HttpPost]
		public ActionResult Feedback(FeedbackViewModel model)
		{
			if (_mailModel.SendFeedbackRequest(CurrentClient.Login, CurrentClient.FullName, CurrentClient.Email, model.FeedbackType, model.Content))
			{
				model.IsFeedbackSend = true;
			}
			else
			{
				model.FeedbackTypes = _feedbackTypeModel.GetAll().OrderBy(x => x.Name).Select(x => x.Name).ToList();
				ModelState.AddModelError("MailError", "Eror sending request, try again.");
			}

			return View(model);
		}
    }
}